package com.javastar.modules.storage.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.javastar.common.result.Result;
import com.javastar.modules.storage.service.StorageConfigService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 第三方文件存储配置表 前端控制器
 * </p>
 *
 * @author Java星球
 * @since 2023-07-25
 */
@RestController
@RequestMapping("/modules/storage-config-entity")
@Api(tags = "第三方文件存储配置")
public class StorageConfigController {
    @Autowired
    private StorageConfigService storageConfigService;

    @PostMapping("uploadSingleFile")
    @ApiOperation(value = "单文件上传")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "上传文件", paramType = "form", required = true, dataType = "MultipartFile"),
            @ApiImplicitParam(name = "type", value = "文件类型 1图片 2视频", required = true, defaultValue = "1", dataType = "int")
    })
    @ApiResponse(code = 200, message = "文件访问路径")
    public Result<String> uploadSingleFile(@RequestParam MultipartFile file, @RequestParam Integer type) {
        String url = storageConfigService.uploadSingleFile(file, type);
        return new Result<String>().ok(url);
    }
}
